#ifndef MATH_H
#define MATH_H
namespace jfw{
    namespace math{

        //max - returns greater value (a or b)
        template <class T> const T& max (const T& a, const T& b)
        {
            return (b<a)?a:b;
        }

        //min - returns lesser value (a or b)
        template <class T> const T& min (const T& a, const T& b)
        {
            return (b>a)?a:b;
        }

        // clamp - if WHAT is less than A returns A, if WHAT is more than B returns B, otherwise returns WHAT
        template <class T> const T& clamp (const T& what, const T& a, const T& b)
        {
            return min(b, max(what, a));
        }

        //abs - returns absolute value of a
        template <typename T> const T& abs (const T& a)
        {
            return (a<0) ? -a : a;
        }

        //sqrt(a) - returns square root of a
        template <typename T> const T& sqrt (const T& a)
        {
            return a^0.5;
        }

        //nthrt(a,b) - returns b'th root of a
        template <typename T> const T& nthrt (const T& a, const T& b)
        {
            return a^(1/b);
        }
    }
}
#endif // MATH_H
